﻿using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using System.Threading;

namespace SPExplorer
{
  static class Program
  {
    [STAThread]
    static void Main()
    {
      //SPContext.Initialize("../test_site");
      string[] args = Environment.GetCommandLineArgs();
      FakeBuilder.CommandLine commandline = new FakeBuilder.CommandLine(args);
      string filepath = commandline.GetString("out", "");
      if (filepath.Length > 0)
      {
        try
        {
          SPExplorerDocument document = new SPExplorerDocument();
          document.ReadFromLocalFarm();
          document.SaveToFile(filepath);
        }
        catch (Exception ex)
        {
          Console.WriteLine("Exception: " + ex.Message);
        }
        return;
      }
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      // force UI thread to Single Thread Appartment model
      Thread uiThread = new Thread(delegate() { Application.Run(new SPExplorerForm()); });
      uiThread.SetApartmentState(ApartmentState.STA);
      uiThread.Start();
    }
  }
}
